<template>
  <div>
    <van-nav-bar
      title="用户登录"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    ></van-nav-bar>

    <van-form>
      <van-field
        v-model="username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      ></van-field>
      <van-field
        v-model="pwd"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      ></van-field>
      <div style="margin: 16px;">
        <van-button round block type="info" @click="onSubmit">提交</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: 'App',
  data(){
    return{
      username: 'zhangsan',
      pwd: '123456',
    }
  },
  methods:{
    onClickLeft() {
      this.$router.push({path:'/Mine'})
    },
    onSubmit() {
      let thta = this;
   
      axios.post('http://localhost:9090/api/login',{
          userName:thta.username,
          pwd:thta.pwd
        })        
        .then(res => {    
          // 登录成功，则把 token 字符串，存储到浏览器本地储存中
          localStorage.setItem("token",res.data.data)
          // 后退一步
          this.$router.go(-1);
          
          // 用于是否登录成功
          this.$store.state.isLogin = true
        })        
        .catch(err => {            
            console.log(err.data)        
        }) 

    },
  }
}
</script>
  
<style scoped>
</style>
